<?php
/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/12
 * Time: 10:13
 */

namespace App\admin\TableView;


use App\admin\TableView\BaseClass\BaseViewList;
use App\Jobs\Fun;
use App\Models\Admin\ApilistModel;
use App\Models\NewsModel;

class NewsView extends BaseViewList
{

    public function get_model()
    {

        return new NewsModel();
    }

    public $topTitle = '咨询';
    public $PageSize = 10;

    public $breadcrumb = '<li><a href="/mcadmin">Home</a></li>
        <li><a href="javascript:;">资讯</a></li>
        ';

    public $html = '';


    //  public $show_add = false; ///显示添加按钮

    /**
     * 获取表格的唯一名字
     */
    public function getName()
    {
        return 'NewsModel';
    }


    /**
     * 需要继承,然后定义每行需要显示的数据格式
     */
    public function Labels()
    {
        return array(
            //   BaseViewList::Button_checkbox=>[],
            'id' => [
                'width' => 40
            ],
            'cid' => ['width' => 80],
            'title' => ['width' => 120],
            'thumb' => ['width' => 200],
            'created_at' => ['width' => 70],
            'status' => ['width' => 50 ],
            'praise' => ['width' => 40 ],
            BaseViewList::Button_control => [

                BaseViewList::Button_Edit,
                BaseViewList::Button_Delete

            ]
        );
    }

    /**
     * 对话框中的各个字段
     */
    public function dialog()
    {
        return array(
            array(
                'zd' => 'title'
            ),
              array(
                'zd' => 'desc'
            ),
            array(
                'zd' => 'content',
                'type' => "texthtml"
            ),
            array(
                'zd' => 'thumb',
                'type' =>self::dialog_text      //dialog_Img
            ),
            array(
                'zd' => 'status',
                'type' => self::dialog_list,
                'data' => [
                    1 => '隐藏',
                    0 => '正常'
                ]
            )

        );
    }

    /**
     * 方便继承,多一层过滤
     */
    public function ModelTohtml($key, $model)
    {
        if ($key == 'status') {
            return $this->ArrayToTitle($model->$key, [
                1 => '隐藏',
                0 => '正常'
            ]);
        }

        if($key==='created_at'){
            return Fun::date($model->$key);
        }
        if($key==='thumb'){
            return $this->toImg(Fun::pImg($model->$key));
        }


        return parent::ModelTohtml($key, $model);
    }

}